package com.zhonghui.dolo.manager.service.impl;

import com.zhonghui.dolo.manager.dao.AdminDao;
import com.zhonghui.dolo.manager.model.Admin;
import com.zhonghui.dolo.manager.model.vo.AdminVo;
import com.zhonghui.dolo.manager.service.AdminService;
import com.zhonghui.dolo.manager.util.MD5Util;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    public AdminVo login(String uname, String upwd) {
        Admin admin = adminDao.findAdminByName(uname);
        if (admin == null) {
            return null;
        }
        String inputPwd = MD5Util.encoder(upwd, admin.getRand());
        if (!inputPwd.equals(admin.getPassword())) {
            return null;
        }
        // 赋值
//        AdminVo adminVo = new AdminVo();
//        adminVo.setAdminId(admin.getAdminId());
//        adminVo.setAdminName(admin.getAdminName());
//        adminVo.setCompanyName(admin.getCompanyName());
//        adminVo.setRoleId(admin.getRoleId());
        AdminVo adminVo = new AdminVo();
        BeanUtils.copyProperties(admin, adminVo);
        return adminVo;
    }
}
